<?php
$this->headTitle('Quản lý thiết bị IT','append');
?>
<!-- Start Table -->
<div class="grid grid_8">
    <div class="box-header">
        <a class="add" href="<?php echo $this->url(array ('controller' => 'equipment' ,'action' => 'add'));?>">Thêm mới</a>
    </div>
    <?php if($this->equipment_list){ ?>
    <div class="box table">
        <table cellspacing="0" class="content_equipment">
        	<thead id="detail">
        		<tr>
        			<td>STT</td>
                    <?php
                        //equipment
                        if(in_array('code',$this->arr_name))
                            echo  '<td>Mã quản lý</td>';
                        if(in_array('equipmentName',$this->arr_name))
                            echo  '<td>Tên thiết bị</td>';
                        if(in_array('position',$this->arr_name))
                            echo  '<td>Vị trí</td>';
                        if(in_array('function',$this->arr_name))
                            echo  '<td>Chức năng</td>';
                        if(in_array('endUser',$this->arr_name))
                            echo  '<td>Người sử dụng</td>';
                        if(in_array('note',$this->arr_name))
                            echo  '<td>Chú thích</td>';
                        if(in_array('categoryName',$this->arr_name))
                            echo  '<td>Nhóm</td>';
                        if(in_array('projectName',$this->arr_name))
                            echo  '<td>Dự án</td>';
                        if(in_array('ip',$this->arr_name))
                            echo  '<td>MAC</td>';
                        if(in_array('iplan1',$this->arr_name))
                            echo  '<td>IP Lan 1</td>';
                        if(in_array('iplan2',$this->arr_name))
                            echo  '<td>IP Lan 2</td>';
                        
                        //item
                        if(in_array('itemName',$this->arr_name))
                            echo  '<td>Item</td>';
                        if(in_array('info',$this->arr_name))
                            echo  '<td>Thông tin</td>';
                        if(in_array('priceItem',$this->arr_name))
                            echo  '<td>Giá mua</td>';
                        if(in_array('startDate',$this->arr_name))
                            echo  '<td>Ngày bắt đầu</td>';
                        if(in_array('history',$this->arr_name))
                            echo  '<td>Lịch sử</td>';
                        if(in_array('owner',$this->arr_name))
                            echo  '<td>Tài sản</td>';
                        
                        echo  '<td>Tuỳ chọn</td>';
                    ?>
        			
        		</tr>
        	</thead>
        	<tbody>
            <?php 
                $i=0; 
                $temp = 'odd';
                foreach($this->equipment_list as $equipment){ 
            ?>
                <tr id="row<?php echo $equipment['equipmentId']; ?>" class="row-<?php echo $temp;?>">
        			<td><?php echo ++$i;?></td>
                    
                    <?php
                        //equipment
                        if(isset($equipment['code']))
                            echo '<td>
                                    <span title="',str_replace('"',"'",$equipment['code']),'">',
                                    $equipment['code'] ? $this->stringTrim(str_replace("\r\n","",$equipment['code']), 40) : '-','
                                    </span>
                                </td>';
                        if(isset($equipment['equipmentName']))
                            echo '<td>
                                    <span title="',str_replace('"',"'",$equipment['equipmentName']),'">',
                                    $equipment['equipmentName'] ? $this->stringTrim(str_replace("\r\n","",$equipment['equipmentName']), 40) : '-','
                                    </span>
                                </td>';
                        if(isset($equipment['position']))
                            echo '<td>
                                    <span title="',str_replace('"',"'",$equipment['position']),'">',
                                    $equipment['position'] ? $this->stringTrim(str_replace("\r\n","",$equipment['position']), 40) : '-','
                                    </span>
                                </td>';
                        if(isset($equipment['function']))
                            echo '<td>
                                    <span title="',str_replace('"',"'",$equipment['function']),'">',
                                    $equipment['function'] ? $this->stringTrim(str_replace("\r\n","",$equipment['function']), 40) : '-','
                                    </span>
                                </td>';
                        if(isset($equipment['endUser']))
                            echo '<td>
                                    <span title="',str_replace('"',"'",$equipment['endUser']),'">',
                                    $equipment['endUser'] ? $this->stringTrim(str_replace("\r\n","",$equipment['endUser']), 40) : '-','
                                    </span>
                                </td>';
                        if(isset($equipment['note']))
                            echo '<td>
                                    <span title="',str_replace('"',"'",$equipment['note']),'">',
                                    $equipment['note'] ? $this->stringTrim(str_replace("\r\n","",$equipment['note']), 40) : '-','
                                    </span>
                                </td>';
                        if(in_array('categoryName',$this->arr_name))
                            echo '<td>
                                    <span title="',str_replace('"',"'",$equipment['categoryName']),'">',
                                    $equipment['categoryName'] ? $this->stringTrim(str_replace("\r\n","",$equipment['categoryName']), 40) : '-','
                                    </span>
                                </td>';
                        if(in_array('projectName',$this->arr_name)){
                            echo '<td>';
                            $stt = 1;
                            foreach($equipment['project_list'] as $project){
                                if($stt == 1)
                                    echo '"',$this->stringTrim(str_replace("\r\n","",$project["projectName"]), 40),'"';
                                else
                                    echo ' - "',$this->stringTrim(str_replace("\r\n","",$project["projectName"]), 40),'"';
                                ++$stt;
                            }
                            echo '</td>';
                        }
                        if(isset($equipment['ip']))
                            echo '<td>
                                    <span title="',str_replace('"',"'",$equipment['ip']),'">',
                                    $equipment['ip'] ? $this->stringTrim(str_replace("\r\n","",$equipment['ip']), 40) : '-','
                                    </span>
                                </td>';
                        if(isset($equipment['iplan1']))
                            echo '<td>
                                    <span title="',str_replace('"',"'",$equipment['iplan1']),'">',
                                    $equipment['iplan1'] ? $this->stringTrim(str_replace("\r\n","",$equipment['iplan1']), 40) : '-','
                                    </span>
                                </td>';
                        if(isset($equipment['iplan2']))
                            echo '<td>
                                    <span title="',str_replace('"',"'",$equipment['iplan2']),'">',
                                    $equipment['iplan2'] ? $this->stringTrim(str_replace("\r\n","",$equipment['iplan2']), 40) : '-','
                                    </span>
                                </td>';
                                
                                
                        //item
                        if(in_array('itemName',$this->arr_name)){
                            echo '<td><table>';
                            foreach($equipment['items_list'] as $item){
    							echo '<tr>
    							       <td style="border-left: 0px;">
                                         <div style="height: 30px;">
                                           <span title="',str_replace('"',"'",$item['itemName']),'">',
                                            $item['itemName'] ? $this->stringTrim(str_replace("\r\n","",$item['itemName']), 9) : '-','
                                           </span>
                                         </div>
                                       </td>
    						        </tr>';
                            }
                            echo '</table></td>';
                        }
                        if(in_array('info',$this->arr_name)){
                            echo '<td><table>';
                            foreach($equipment['items_list'] as $item){
    							echo '<tr>
    							       <td style="border-left: 0px;">
                                         <div style="height: 30px;">
                                           <span title="',str_replace('"',"'",$item['info']),'">',
                                            $item['info'] ? $this->stringTrim(str_replace("\r\n","",$item['info']), 9) : '-','
                                           </span>
                                         </div>
                                       </td>
    						        </tr>';
                            }
                            echo '</table></td>';
                        }
                        if(in_array('priceItem',$this->arr_name)){
                            echo '<td><table>';
                            foreach($equipment['items_list'] as $item){
    							echo '<tr>
    							       <td style="border-left: 0px;">
                                         <div style="height: 30px;">
                                           <span title="',$item['priceItem'] ? number_format($item['priceItem'], 0, ',', '.') : '-','">',
                                            $item['priceItem'] ? number_format($item['priceItem'], 0, ',', '.') : '-','
                                           </span>
                                         </div>
                                       </td>
    						        </tr>';
                            }
                            echo '</table></td>';
                        }
                        if(in_array('startDate',$this->arr_name)){
                            echo '<td><table>';
                            foreach($equipment['items_list'] as $item){
    							echo '<tr>
    							       <td style="border-left: 0px;">
                                         <div style="height: 30px;">
                                           <span title="',$item['startDate'] ? $this->time()->dataToDate($item['startDate']) : '-','">',
                                            $item['startDate'] ? $this->time()->dataToDate($item['startDate']) : '-','
                                           </span>
                                         </div>
                                       </td>
    						        </tr>';
                            }
                            echo '</table></td>';
                        }
                        if(in_array('history',$this->arr_name)){
                            echo '<td><table>';
                            foreach($equipment['items_list'] as $item){
    							echo '<tr>
    							       <td style="border-left: 0px;">
                                         <div style="height: 30px;">
                                           <span title="',str_replace('"',"'",$item['history']),'">',
                                            $item['history'] ? $this->stringTrim(str_replace("\r\n","",$item['history']), 9) : '-','
                                           </span>
                                         </div>
                                       </td>
    						        </tr>';
                            }
                            echo '</table></td>';
                        }
                        if(in_array('owner',$this->arr_name)){
                            echo '<td><table>';
                            foreach($equipment['items_list'] as $item){
    							echo '<tr>
    							       <td style="border-left: 0px;">
                                         <div style="height: 30px;">
                                           <span title="',str_replace('"',"'",$item['owner']),'">',
                                            $item['owner'] ? $this->stringTrim(str_replace("\r\n","",$item['owner']), 9) : '-','
                                           </span>
                                         </div>
                                       </td>
    						        </tr>';
                            }
                            echo '</table></td>';
                        }
                    ?>
                    
                    
    			<td class="tc">
    				<a href="<?php echo $this->url(array ( 'controller' => 'equipment' ,'action' => 'detail' , 'id' => $equipment['equipmentId'] )); ?>">
                        <img src="image/icons/small/icon_info.png" title="xem chi tiết" border="0">
                    </a>
    				<a href="<?php echo $this->url(array ( 'controller' => 'equipment' ,'action' => 'edit' ,'id' => $equipment['equipmentId']));?>">
                        <img src="image/icons/small/icon_edit.png" title="sửa" border="0">
                    </a>
    				<a href="<?php echo $this->url(array ( 'controller' => 'equipment' ,'action' => 'delete' , 'id' => $equipment['equipmentId'] )); ?>">
                        <img src="image/icons/small/icon_delete.png" title="xóa" border="0">
                    </a>
    			</td>
    		</tr>
            <?php 
                    if($temp == 'odd')
                        $temp = 'even';
                    else
                        $temp = 'odd';
                } 
            ?>
        
             </tbody>
             <!-- BEGIN: PAGINATION (FOOT) -->
             <tfoot>
        		<tr>
        			<td colspan="<?php echo count($this->arr_header)+2?>">
        				<div class="container">
        					<div class="pagination">
        						<?php
        							echo $this->paginationControl($this->panigator,'Sliding','paginator.phtml');
        						?>
        					</div>
        				</div>
        			</td>
        		</tr>
        	  </tfoot>
        	  <!-- END: PAGINATION (FOOT) -->
        </table>
    	<p align="center" style="clear:none;">
            <a style="text-decoration: none; color: #1f92ff;" href='<?php echo $this->url(array('action'=>'exportexcel','type'=>'allequipment'))?>' title="xuất Excel">
                <img src='image/icons/small/icon_table-export.png' /><br />Xuất file excel
            </a>
        </p>
    </div>
    <?php }else{ ?>
    <div class="notification error"><span class="strong">Chưa có dữ liệu</span></div>
    <?php } ?>
</div>
<script>
	var w = $(".content_equipment").width();
	$(".grid .box.table").css('width', w);
</script>
